package com.oa.modules.approvalsec1.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.oa.modules.approvalsec1.entity.BankAccountEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 银行开户
 *
 * @author jiangwei
 * @email 785297226@qq.com
 * @date 2021-07-29 16:23:38
 */
@Mapper
public interface BankAccountDao extends BaseMapper<BankAccountEntity> {


    /**
     * 查询总条数
     *
     * @author jiangwei
     * @email 785297226@qq.com
     * @date 2021-07-29 16:23:38
     * @Description 查询分页数据
     */
    @Select("<script>SELECT COUNT( 1 ) FROM (" +
            "select t1.* from bank_account t1  " +
            "where 1=1 " +
            "<if test = 'params != null '> " +
            "and t1.`STATUS` = #{params.status} " +
            "<if test='params.companyName != null'>and t1.company_name = #{params.companyName}  </if> " +
            "<if test='params.createOper != null'>and t1.create_oper = #{params.createOper}  </if> " +
            "<if test='params.unPush != null and params.unPush==1'>and t1.SOCIAL_TYPE='未知' </if> " +
            "<if test='params.bankUserId != null'> and t1.bank_name in (select BANK_NAME from user_bank t2 where t2.userid = #{params.bankUserId}) </if> " +
            ") </if> TOTAL</script>")
    long findPage(@Param("params") Map<String, Object> params);


    /**
     * 查询分页数据
     *
     * @author jiangwei
     * @email 785297226@qq.com
     * @date 2021-07-29 16:23:38
     * @Description 查询分页数据
     */
    @Select("<script>select t1.* from bank_account t1 " +
            "where 1=1 " +
            "and t1.`STATUS` = #{params.status} " +
            "<if test='params.companyName != null'>and t1.company_name = #{params.companyName}  </if> " +
            "<if test='params.createOper != null'>and t1.create_oper = #{params.createOper}  </if> " +
            "<if test='params.unPush != null and params.unPush==1'>and t1.SOCIAL_TYPE='未知' </if> " +
            "<if test='params.bankUserId != null'> and t1.bank_name in (select BANK_NAME from user_bank t2 where t2.userid = #{params.bankUserId}) </if> " +
            "ORDER BY t1.CREATE_DATE desc</script>")
    List<BankAccountEntity> findRecords(IPage<BankAccountEntity> page, @Param("params") Map<String, Object> params);


    /**
     * 根据公司名称查询信息
     *
     * @author jiangwei
     * @email 785297226@qq.com
     * @date 2021-07-29 16:23:38
     * @Description 查询分页数据
     */
    @Select("<script>select t1.* from bank_account t1 " +
            "where 1=1 " +
            "and t1.`STATUS` = #{status} " +
            "<if test='companyName != null'>and t1.company_name = #{companyName}  </if> " +
            "ORDER BY t1.CREATE_DATE desc</script>")
    BankAccountEntity getByCompanyName(@Param("status") String status, @Param("companyName") String companyName);

    /**
     * 查询分页数据
     *
     * @author jiangwei
     * @email 785297226@qq.com
     * @date 2021-04-08 10:30:10
     * @Description 查询分页数据
     */
    @Select("<script>select t1.* from bank_account t1 " +
            "where 1=1 " +
            "<if test='params.startDate != null'> and t1.CREATE_DATE &gt; #{params.startDate}  </if> " +
            "<if test='params.endDate != null'> and t1.CREATE_DATE &lt; #{params.endDate} </if> " +
            "ORDER BY t1.CREATE_DATE desc</script>")
    List<BankAccountEntity> queryList(@Param("params") Map<String, Object> params);

    /**
     * 根据userId查询当前用户的开户信息
     *
     * @param params
     * @return
     */
    BankAccountEntity newBankInfo(@Param("params") Map<String, Object> params);

    /**
     * 根据社会类型查询开户列表数量
     *
     * @param params
     * @return
     */
    @Select("<script>SELECT COUNT(1) FROM (" +
            "select t1.* from bank_account t1 " +
            "where 1=1 " +
            "<if test='params != null'>" +
            "and t1.`SOCIAL_TYPE` = #{params.socialType} " +
            "</if> ) TOTAL</script>")
    long socialListCount(@Param("params") Map<String, Object> params);

    /**
     * 根据社会类型分页查询开户列表
     *
     * @param page
     * @return
     */
    @Select("select * from bank_account t1 where t1.`SOCIAL_TYPE` LIKE '%${params.socialType}%'")
    List<BankAccountEntity> socialList(IPage<BankAccountEntity> page, @Param("params") Map<String, Object> params);

}
